package com.yjd.pub.funds.service;

import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.funds.enums.FundsIncomeEnum;
import com.yjd.comm.funds.enums.FundsRefTableEnum;
import com.yjd.comm.funds.enums.FundsTypeEnum;
import com.yjd.comm.funds.model.FundsDataModel;
import com.yjd.comm.funds.service.IFundsDataService;
import com.yjd.pub.funds.dao.IFundsDataDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <b>description</b>：用户资金明细表业务实现<br>
 * <b>time</b>：2017-09-19 15:39:19 <br>
 * <b>author</b>：  carl
 */
@Service("fundsDataService")
public class FundsDataServiceImpl extends BaseServiceImpl implements IFundsDataService {

	/**
	 * 插入
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public FundsDataModel insert(FundsDataModel model) throws Exception {
		return this.fundsDataDao.insertModel(model, true);
	}

	/**
	 * 更新
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public int update(FundsDataModel model) throws Exception {
		return this.fundsDataDao.updateModel(model, true);
	}

	/**
	 * 根据id删除
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(long id) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("id", id);
		return this.fundsDataDao.deleteModel(paramMap, true);
	}

	/**
	 * 新增资金流水 (公用方法)
	 *
	 * @param user_id
	 * @param price
	 * @param balance
	 * @param incomeEnum
	 * @param typeEnum
	 * @param ref_id
	 * @param refTableEnum
	 * @param currtime
	 * @throws Exception
	 */
	@Override
	public void insertFundsData(Long user_id, Double price, Double balance, FundsIncomeEnum incomeEnum,
								FundsTypeEnum typeEnum, String ref_id, FundsRefTableEnum refTableEnum, Long currtime) throws Exception {
		FundsDataModel dataModel = new FundsDataModel();
		dataModel.setUser_id(user_id);
		dataModel.setPrice(price);
		dataModel.setBalance(balance);
		dataModel.setIncome(incomeEnum.getCode());
		dataModel.setType(typeEnum.getCode());
		dataModel.setRef_id(ref_id);
		dataModel.setRef_table(refTableEnum.getCode());
		dataModel.setUpdate_time(currtime);
		this.fundsDataDao.insertModel(dataModel,true);

	}

	@Resource
	private IFundsDataDao fundsDataDao;

	@Override
	public IBaseDao getBaseDao() {
		return this.fundsDataDao;
	}

}
